<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>股票信息 - 后台管理</title>
  <link rel="stylesheet" href="/static/base.css">
  <link rel="stylesheet" href="/static/components.css">
  <link rel="stylesheet" href="/static/pages.css">
  <link rel="stylesheet" href="/static/admin/admin.css">
</head>
<body>
  <div class="admin-layout">
    <!-- 顶部导航 -->
    <div class="admin-header">
      <h2>股票信息</h2>
      <div>
        <button class="btn" onclick="location.href='/'">返回前台</button>
        <button class="btn" onclick="logout()">退出</button>
      </div>
    </div>

    <!-- 主体内容 -->
    <div class="admin-main">
      <!-- 左侧导航（公共组件注入） -->
      <div class="admin-sidebar"></div>

      <!-- 右侧内容区域 -->
      <div class="admin-content">
        <div class="content-page active">
          <h3>股票信息概览</h3>
          <p class="page-description">管理股票信息、板块信息和板块关联数据</p>

          <!-- 数据统计面板 -->
          <div class="strategy-stats">
            <h4>数据统计</h4>
            <div class="stats-grid">
              <div class="stat-item">
                <span class="stat-label">股票信息</span>
                <span id="stockinfo-count" class="stat-value">-</span>
              </div>
              <div class="stat-item">
                <span class="stat-label">板块信息</span>
                <span id="block-count" class="stat-value">-</span>
              </div>
              <div class="stat-item">
                <span class="stat-label">板块关联</span>
                <span id="blockinfo-count" class="stat-value">-</span>
              </div>
            </div>
          </div>

          <!-- 快速操作 -->
          <div class="content-grid">
            <div class="content-card">
              <h4>数据管理</h4>
              <p>管理股票信息、板块信息和板块关联数据</p>
              <div class="card-actions">
                <button class="btn btn-primary" onclick="location.href='/admin/data-management'">进入管理</button>
              </div>
            </div>

            <div class="content-card">
              <h4>标签管理</h4>
              <p>为股票设置长期标签，支持自定义分类</p>
              <div class="card-actions">
                <button class="btn btn-primary" onclick="location.href='/admin/label-management'">管理标签</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="/static/admin/components/sidebar.js"></script>
  <script>
    // 页面加载时获取数据统计信息并注入侧边栏
    document.addEventListener('DOMContentLoaded', function() {
      loadDataStats();
      injectAdminSidebar('/admin/fundamental');
    });

    // 加载数据统计信息
    async function loadDataStats() {
      try {
        const response = await fetch('/admin/api/fundamental/stats');
        const data = await response.json();
        
        if (data.success) {
          document.getElementById('stockinfo-count').textContent = data.stockinfo_count || 0;
          document.getElementById('block-count').textContent = data.block_count || 0;
          document.getElementById('blockinfo-count').textContent = data.blockinfo_count || 0;
        } else {
          console.error('获取数据统计失败:', data.error);
          document.getElementById('stockinfo-count').textContent = '0';
          document.getElementById('block-count').textContent = '0';
          document.getElementById('blockinfo-count').textContent = '0';
        }
      } catch (error) {
        console.error('加载数据统计失败:', error);
        document.getElementById('stockinfo-count').textContent = '0';
        document.getElementById('block-count').textContent = '0';
        document.getElementById('blockinfo-count').textContent = '0';
      }
    }

    // 退出登录
    async function logout(){
      try{ 
        await fetch('/admin/logout', {method:'POST'}); 
        location.href='/admin/login'; 
      }catch(e){ 
        location.href='/admin/login'; 
      }
    }
  </script>
</body>
</html>
